package com.cgs.query.executor

import com.cgs.query.domain.MappedStatement
import com.cgs.query.exception.QueryException

/**执行器*/
interface Executor {

    fun start()

    fun isStart(): Boolean

    fun close(forceRollback: Boolean)

    fun isClosed(): Boolean

    fun execute(ms: MappedStatement, param: Map<String, Any?>?, timeout: Int?): Any

}

/**
 * 执行上下文
 */
class ExecutionContext(val mappedStatement: MappedStatement,
                       val param: Map<String, Any?>) {
    var dbType: String? = null
}

interface ExecuteAspectHandler {

    fun before(args: ExecuteArgs)

    fun after(result: Any?)

    fun exception(e: QueryException)
}

class ExecuteArgs(args: Array<Any>) {
    val projectName: String = args[0] as String
    val name: String = args[1] as String
    val param: Map<String, *>? = args[2] as? Map<String, *>
    val timeout: Int? = args[3] as? Int
}